﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QuanLyBepAnTuThien
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }
        connect cn = new connect();
        public void battatmenu(bool val)
        {
            btnmenu_dangxuat.Enabled = val;
            btnmenu_themnguoidung.Enabled = val;
            btnmenuQuanLyNguoiDung.Enabled = val;
            btnDoiMatKhau.Enabled = val;
            btnmenu_SaoLuuCSDL.Enabled = val;
            btnmenu_phuchoiCSDL.Enabled = val;
            btnQLNhanVien.Enabled = val;
            btnDanhSachTo.Enabled = val;
            btnPhanCongQuanLy.Enabled = val;
            btnQuanLyDungCu.Enabled = val;
            btnQLChiTieu.Enabled = val;
            btnQLSoVang.Enabled = val;
            btnQLManhThuongQuan.Enabled = val;
            btnQLBienBan.Enabled = val;
            btnThongKeNhanVien.Enabled = val;
            btntkNhanVien.Enabled = val;
            btnThongKeTaiSan.Enabled = val;
            btnThongKeThuChi.Enabled = val;
            btnThongKeUngHo.Enabled = val;
            bntmenu_dangnhap.Enabled = !val;
        }
        public void phanquyen()
        {
            if (login._user == null)
            {
                battatmenu(false);
            }
            else
            {
                if (login.Quyen == "Admin")
                {
                    battatmenu(true);
                    lbTenDangNhap.Text = login._user;
                }
                else
                {
                    battatmenu(false);
                }
            }
        }
        public void frmMain_Load(object sender, EventArgs e)
        {
            try
            {
                cn.ketnoi();
                this.WindowState = FormWindowState.Maximized;
                phanquyen();
            }
            catch
            {
                MessageBox.Show("Kết nối đến CSDL không thành công!. Vui lòng thực hiện các thao tác tiếp theo để thiết lập lại thông tin kết nối","Thông Báo",MessageBoxButtons.OK,MessageBoxIcon.Error);
                frmThietLapKetNoi frmthietlapketnoi = new frmThietLapKetNoi();
                frmthietlapketnoi.ShowDialog();
            }
        }

        private void btnDoiMatKhau_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmDoiMatKhau _frmDoiMatKhau = new frmDoiMatKhau();
            _frmDoiMatKhau.ShowDialog();
            Application.Restart();

        }

        private void btnmenuQuanLyNguoiDung_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            panelMain.Controls.Clear();
            UcQuanLyNguoiDung _ucQuanLyNguoiDung = new UcQuanLyNguoiDung();
            _ucQuanLyNguoiDung.Dock = DockStyle.Fill;
            panelMain.Controls.Add(_ucQuanLyNguoiDung);
        }

        private void bntmenu_dangnhap_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmLogin _frmLogin = new frmLogin();
            _frmLogin.ShowDialog();
            //this.WindowState = FormWindowState.Maximized;
            phanquyen();
            
        }

        private void btnQLNhanVien_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            panelMain.Controls.Clear();
            UcQuanLyNhanVien ucqlnv = new UcQuanLyNhanVien();
            ucqlnv.Dock = DockStyle.Fill;
            panelMain.Controls.Add(ucqlnv);
        }

        private void btnDanhSachTo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            panelMain.Controls.Clear();
            UcQuanLyTo _ucQuanLyTo = new UcQuanLyTo();
            _ucQuanLyTo.Dock = DockStyle.Fill;
            panelMain.Controls.Add(_ucQuanLyTo);
        }

        private void btnPhanCongQuanLy_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            panelMain.Controls.Clear();
            UcChiTietTo _ucChiTietTo = new UcChiTietTo();
            _ucChiTietTo.Dock = DockStyle.Fill;
            panelMain.Controls.Add(_ucChiTietTo);
        }

        private void btnQuanLyDungCu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            panelMain.Controls.Clear();
            UcQuanLyNguyenLieuDungCu _ucQuanLyDCNL = new UcQuanLyNguyenLieuDungCu();
            _ucQuanLyDCNL.Dock = DockStyle.Fill;
            panelMain.Controls.Add(_ucQuanLyDCNL);
        }

        private void btnQLChiTieu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            panelMain.Controls.Clear();
            UcQuanLyChiTieu _ucqlct = new UcQuanLyChiTieu();
            _ucqlct.Dock = DockStyle.Fill;
            panelMain.Controls.Add(_ucqlct);
        }

        private void btnQLSoVang_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            panelMain.Controls.Clear();
            UcQuanLySoVang UcsoVang = new UcQuanLySoVang();
            UcsoVang.Dock = DockStyle.Fill;
            panelMain.Controls.Add(UcsoVang);
        }

        private void btnQLManhThuongQuan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            panelMain.Controls.Clear();
            UcMTQ ucmtq = new UcMTQ();
            ucmtq.Dock = DockStyle.Fill;
            panelMain.Controls.Add(ucmtq);
        }

        private void btnQLBienBan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            panelMain.Controls.Clear();
            UcBienBanBanGiao ucbienban = new UcBienBanBanGiao();
            ucbienban.Dock = DockStyle.Fill;
            panelMain.Controls.Add(ucbienban);
        }

        private void btntkNhanVien_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            panelMain.Controls.Clear();
            UcThongKeNhanVien ucthongkenhanvien = new UcThongKeNhanVien();
            ucthongkenhanvien.Dock = DockStyle.Fill;
            panelMain.Controls.Add(ucthongkenhanvien);
        }

        private void btnThongKeTaiSan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //panelMain.Controls.Clear();
            //UcThongKeThuChi
            //ucthongkenhanvien.Dock = DockStyle.Fill;
            //panelMain.Controls.Add(ucthongkenhanvien);
        }

        private void btnThongKeThuChi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            panelMain.Controls.Clear();
            UcThongKeThuChi uctkthuchi = new UcThongKeThuChi();
            uctkthuchi.Dock = DockStyle.Fill;
            panelMain.Controls.Add(uctkthuchi);
        }

        private void btnmenu_phuchoiCSDL_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void btnmenu_dangxuat_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            login._user = null;
            login._pass = null;
            Application.Restart();
        }

        private void btnLichTRuc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            panelMain.Controls.Clear();
            UcPhanCongLichTruc ucphancong = new UcPhanCongLichTruc();
            ucphancong.Dock = DockStyle.Fill;
            panelMain.Controls.Add(ucphancong);           
        }        
        /*
        private void frmMain_Shown(object sender, EventArgs e)
        {
            frmLogin _frmLogin = new frmLogin();
            _frmLogin.ShowDialog();
        }*/
        
    }
}
